package com.sgb.jicai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.FreightRulesBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

public class MethodAdapter  extends BaseRecycleAdapter<FreightRulesBean> {

    public MethodAdapter(Context context, List<FreightRulesBean> list) {
        super(context, R.layout.item_jc_method, list);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        holder.itemView.findViewById(R.id.rl_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //删除数据的操作
                datas.remove(position);
                notifyDataSetChanged();
                onDelete.Delete();
            }
        });
        if (datas.size()>1){
            holder.itemView.findViewById(R.id.rl_delete).setVisibility(View.VISIBLE);
        }else {
            holder.itemView.findViewById(R.id.rl_delete).setVisibility(View.GONE);
        }
    }

    @Override
    public void convert(ItemViewHolder holder, FreightRulesBean entity) {
        holder.setBinding(BR.viewModel, entity);
    }
    private onDelete onDelete;

    public void setOnDelete(onDelete onDelete) {
        this.onDelete = onDelete;
    }

    public interface onDelete{
        void Delete();
    }
}
